package com.geticsen.leetcode;

//https://leetcode-cn.com/problems/longest-common-prefix/
public class Solution_14 {
    public String longestCommonPrefix(String[] strs) {
        String s = strs[0];

        for (int i = 1; i < strs.length; i++) {
            s = split(strs[i], s);
        }
        return s;
    }

    private String split(String index, String string) {
        int len = 0;
        while (len < index.length() && len < string.length() && index.charAt(len) == string.charAt(len)) {
            len++;
        }
        return string.substring(0, len);
    }
}
